home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0030_Another Which CPU.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  3KB  |  154 lines

  1. >     Hi!  I was wondering.. does anyone have any TP codes to find
  2.  > out what type
  3.  > of machine (ie. XT, 286, 386, 486, Pentium, etc) that the user
  4.  > is running?
  5.  > The type of coding (Inline Assembly or BASM).. I don't care..
  6.  > just make sure
  7.  > that it is usable by Turbo Pascal 6.0 =8)  Thanks!
  8.  
  9. {
  10.   GetCPU                             Byte
  11.   ───────────────────────────────────────
  12.   Ermittelt den arbeitenden CPU-Typ.  Der
  13.   zurückgelieferte Code entspricht:
  14.  
  15.      0 - Intel 8088
  16.      1 - Intel 8086
  17.      2 - NEC V20
  18.      3 - NEC V30
  19.      4 - Intel 80188
  20.      5 - Intel 80186
  21.      6 - Intel 80286 (or Harris or... whatever)
  22.      7 - Intel 80386 (or AMD or Cyrix (?) or... whatever)
  23.      8 - Intel 80486 (or AMD or Cyrix (?) or... ;))
  24.      9 - Intel Pentium (still looking forward for clones... ;))
  25. }
  26. Function GetCPU: Byte; Assembler;
  27. Const processor: Byte= $FF;
  28. Asm
  29.     mov  al, processor
  30.     cmp  al, 0FFh
  31.     jne  @get_out
  32.     pushf
  33.     xor  bx,bx
  34.     push bx
  35.     popf
  36.     pushf
  37.     pop  bx
  38.     and  bx,0F000h
  39.     cmp  bx,0F000h
  40.     je   @no286
  41.     mov  bx,07000h
  42.     push bx
  43.     popf
  44.     pushf
  45.     pop  bx
  46.     and  bx,07000h
  47.     jne  @test486
  48.     mov  dl,6
  49.     jmp  @end
  50. @test486:
  51.     mov  dl,7
  52.     xor  si,si
  53.     mov  ax,cs
  54. {$IFDEF DPMI}
  55.     add  ax,SelectorInc
  56. {$ENDIF}
  57.     mov  es,ax
  58.     mov  byte ptr es:[@queue486+11], 46h     { 46h == "INC SI" }
  59. @queue486:
  60.     nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop
  61.     or   si,si
  62.     jnz  @end
  63.     inc  dl
  64.     db   66h ; pushf      { pushfd }
  65.     db   66h ; pushf      { pushfd }
  66.     db   66h ; pop  ax    { pop eax }
  67.     db   66h ; mov  cx,ax { mov ecx,eax }
  68.     db   66h,35h
  69.     db   00h,00h,20h,00h  { xor eax,(1 shl 21) (Pentium ID flag) }
  70.     db   66h ; push ax    { push eax }
  71.     db   66h ; popf       { popfd }
  72.     db   66h ; pushf      { pushfd }
  73.     db   66h ; pop  ax    { pop eax }
  74.     db   66h,25h
  75.     db   00h,00h,20h,00h  { and eax,(1 shl 21) }
  76.     db   66h,81h,0E1h
  77.     db   00h,00h,20h,00h  { and ecx,(1 shl 21) }
  78.     db   66h ; cmp ax,cx  { cmp eax,ecx }
  79.     je   @is486
  80.     inc  dl
  81. @is486:
  82.     db   66h ; popf       { popfd }
  83.     jmp  @end
  84. @no286:
  85.     mov  dl,5
  86.     mov  al,0FFh
  87.     mov  cl,21h
  88.     shr  al,cl
  89.     jnz  @testdatabus
  90.     mov  dl,2
  91.     sti
  92.     xor  si,si
  93.     mov  cx,0FFFFh
  94. {$IFDEF DPMI}
  95.     push es
  96.     push ds
  97.     pop  es
  98. {$ENDIF}
  99.     rep  seges lodsb      { == rep lods byte ptr es:[si] }
  100. {$IFDEF DPMI}
  101.     pop  es
  102. {$ENDIF}
  103.     or   cx,cx
  104.     jz   @testdatabus
  105.     mov  dl,1
  106. @testdatabus:
  107.     push cs
  108. {$IFDEF DPMI}
  109.     pop  ax
  110.     add  ax,SelectorInc
  111.     mov  es,ax
  112. {$ELSE}
  113.     pop  es
  114. {$ENDIF}
  115.     xor  bx,bx
  116.     std
  117.     mov  al,90h
  118.     mov  cx,3
  119.     call @ip2di
  120.     cli
  121.     rep  stosb
  122.     cld
  123.     nop; nop; nop
  124.     inc  bx
  125.     nop
  126.     sti
  127.     or   bx,bx
  128.     jz   @end      { v20 or 8086 or 80186 }
  129.     cmp  dl,1
  130.     je   @its8088
  131.     cmp  dl,2
  132.     je   @itsV30
  133.     cmp  dl,5
  134.     jne  @end
  135.     mov  dl,4
  136.     jmp  @end
  137. @its8088:
  138.     xor  dl,dl
  139.     jmp  @end
  140. @itsV30:
  141.     mov  dl,3
  142.     jmp  @end
  143. @ip2di:
  144.     pop  di
  145.     push di
  146.     add  di,9
  147.     retn
  148. @end:
  149.     popf
  150.     mov  al,dl
  151.     mov  processor,al
  152. @get_out:
  153. End;
  154.